import { Utils } from './../../Global/Utils';
//------------------------------------------------------------
// * Author         : Ekko
// * Description    : UI管理类
//------------------------------------------------------------

export const enum ui_level_type {
    NONE = 0,
    POP = 1, 
    WINDOW = 2,
    PAGE = 3,
    HIDE = 4,
}

export class UIMgr {
    private static inst: UIMgr;

    UIRoot : cc.Node = null;
    UIRootPath : string = "Canvas/UIRoot";

    pop_level: cc.Node = null;
    window_level: cc.Node = null;
    page_level: cc.Node = null;
    hide_level: cc.Node = null;
    
    private constructor() {
    }

    static getInst(): UIMgr {
        if (!this.inst) {
            this.inst = new UIMgr();
        }

        return this.inst;
    }

    create(): void {
        this.UIRoot = cc.find(this.UIRootPath);
        this.pop_level = cc.find(this.UIRootPath + "/Pop");
        this.window_level = cc.find(this.UIRootPath + "/Window");
        this.page_level = cc.find(this.UIRootPath + "/Page");
        this.hide_level = cc.find(this.UIRootPath + "/Hide");
    }

    show(path: string, type: ui_level_type): void{
        switch (type) {
            case ui_level_type.POP:
                Utils.loadRes(path, this.pop_level);
                break;
            case ui_level_type.WINDOW:
                Utils.loadRes(path, this.window_level);
                break;
            case ui_level_type.PAGE:
                Utils.loadRes(path, this.page_level);
                break;
            default:
                break;
        }
    }

    hide(hideObj: cc.Node): void {
        hideObj.isValid = false;
        hideObj.setParent(this.hide_level);
    }


    getRoot(): cc.Node {
        return this.UIRoot;
    }
}